﻿using MediatR;
using Production_Get.API.Infrastructures.Interfaces;
using Return.Enum;
using THE_WIND_RISES.Common.Domans.BasicInformation.Materials;
using THE_WIND_RISES.Common.Dtos;

namespace Production_Get.API.Application.MaterialManagement
{
    public class ItemUnitSeachHandler:IRequestHandler<ItemUnitSeachCommon,Result>
    {
        private readonly IBaseRepositoryGet<ItemUnit> ItemUnitRepository;
        public ItemUnitSeachHandler(IBaseRepositoryGet<ItemUnit> itemUnitRepository)
        {
            ItemUnitRepository = itemUnitRepository;
        }
        
        public async Task<Result> Handle(ItemUnitSeachCommon request, CancellationToken cancellationToken)
        {
            var result = new Result() { Code = (int)CommonErrorCodes.Search };
            string sql = "SELECT * FROM ItemUnit Where ChooseId=" + request.ChooseId;
            var list = ItemUnitRepository.GetAll(sql, default).FirstOrDefault();
            result.Code = (int)CommonErrorCodes.Success;
            result.Data = list;
            result.Msg = "物料单位显示";

            return result;
        }
    }
}
